package com.Cheng.controller;

import com.Cheng.pojo.Buuks;
import com.Cheng.service.BuukService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Author Cheng
 * @Date 2022/4/10 16:40
 */
@Controller
@RequestMapping("/buuk")
public class BuukController {
    @Autowired
    @Qualifier("BuukServiceImpl")
    private BuukService buukService;

    @RequestMapping("/allBuuk")
    public String list(Model model){
        List<Buuks> list = buukService.queryAllBuuk();
        model.addAttribute("list", list);
        return "allBuuk";
    }


    @RequestMapping("/toAddBuuk")
    public String toAddPaper() {
        return "addBuuk";
    }

    @RequestMapping("/addBuuk")
    public String addPaper(Buuks buuks) {
        System.out.println(buuks);
        buukService.addBuuk(buuks);
        return "redirect:/buuk/allBuuk";
    }

    @RequestMapping("/allBuuk1")
    public String list1(Model model){
        List<Buuks> list = buukService.queryAllBuuk();
        model.addAttribute("list", list);
        return "two2";
    }

    @RequestMapping("/updateBuuk")
    public String updateBuuk(Model model, Buuks buuk) {
        buukService.updateBuuk(buuk);
        Buuks buuks = buukService.queryBuukById(buuk.getBuukID());
        model.addAttribute("buuk", buuks);
        return "redirect:/buuk/allBuuk";
    }

    @RequestMapping("/del")
    public String deleteBuuk(int id){
        buukService.deleteBuukById(id);
        return "redirect:/buuk/allBuuk";
    }
}
